home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / gfx / fract / FlashMandelWOS.lha / FlashMandel / Developer / Modules / FixedMath / Mandeln68K_Fixed.c < prev   
Encoding:
C/C++ Source or Header  |  2002-08-05  |  1.2 KB  |  65 lines

  1. #include <exec/types.h>
  2. #include <proto/utility.h>
  3. #include <math.h>
  4. #include <i64.h>
  5. #include <flashmandel.h>
  6.  
  7. // fixed point math 6.58
  8. #define INTEGER_BITS 6L
  9. #define FLOAT_BITS   58L
  10. #define H_FLOAT_BITS (FLOAT_BITS / 2)
  11.  
  12. #define KMULT (1L << H_FLOAT_BITS)
  13.  
  14. #ifdef FIXEDPOINT_MATH
  15.  
  16. WORD Mandeln68K_Fixed (ULONG Iterazioni,ULONG Power,LDouble Cre,LDouble Cim)
  17. {                                                        
  18. register WORD Exp;
  19. FIXED_64 zr,zi,zr2,zi2,cre,cim,tmp;
  20. FIXED_64 maxdist;
  21.  
  22. tmp = i64_uset (4L);
  23. maxdist = i64_lshift (tmp,FLOAT_BITS);
  24.  
  25. tmp = i64_uset (KMULT);
  26. cre = i64_set ((LONG) (Cre * KMULT));
  27. cim = i64_set ((LONG) (Cim * KMULT));
  28.  
  29. cre = i64_mul (cre,tmp);
  30. cim = i64_mul (cim,tmp);
  31.  
  32. zr = cre;
  33. zi = cim;
  34.  
  35.   do {
  36.        for (Exp = Power; Exp != -1; Exp--)
  37.        {
  38.            zi = i64_urshift (zi,H_FLOAT_BITS);
  39.  
  40.            zr = i64_urshift (zr,H_FLOAT_BITS);
  41.  
  42.            zi2 = i64_mul (zi,zi);
  43.  
  44.            zi = i64_mul (zr,zi);
  45.  
  46.            zr2 = i64_mul (zr,zr);
  47.  
  48.            zr = i64_sub (zr2,zi2);
  49.  
  50.            zi = i64_add (zi,zi);
  51.        }
  52.  
  53.        if (i64_cmp (i64_add (zr2,zi2),maxdist) == I64_GREATER ) return Iterazioni;
  54.  
  55.        zi = i64_add (zi,cim);
  56.  
  57.        zr = i64_add (zr,cre);
  58.  
  59.      } while (--Iterazioni != -1);
  60.  
  61.   return 0;
  62. }
  63. #endif
  64.  
  65.